package com.dingwei.superiordiary.mvp.presenter;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.ConfirmOrderBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.OrderPayBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.net.URL;

/**
 * Created by lihao on 2017/9/12.
 */

public class ConfirmOrderPresenter extends basePresenter {

    private Contract.ConfirmOrderView confirmOrderView;

    public ConfirmOrderPresenter(Contract.ConfirmOrderView view) {
        super(view);
        this.confirmOrderView = view;
    }

    public void getData(String car_ids) {

        RequestParams rp = new RequestParams(URLS.HOST + URLS.confirmBuyCartId);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("id", car_ids);
        x.http().post(rp, new myCallback(BaseActivity.context, ConfirmOrderBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                ConfirmOrderBean bean = (ConfirmOrderBean) baseBean;
                confirmOrderView.setData(bean);
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                confirmOrderView.onFail();
            }
        });
    }

    public void orderByCart(final String payType, String id, String address_id) {

        RequestParams rp = new RequestParams(URLS.HOST+URLS.orderByCart);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("id", id);
        rp.addBodyParameter("address_id", address_id);
        x.http().post(rp, new myCallback(BaseActivity.context, OrderPayBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                OrderPayBean bean = (OrderPayBean) baseBean;
                if (payType.equals("wx")){
                    confirmOrderView.wxPay(bean);
                }else {
                    confirmOrderView.alipay(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }
}
